package com.example.yuntiku.dao.impl;

import com.example.yuntiku.dao.BaseDao;
import com.example.yuntiku.dao.PagerquestionDao;
import com.example.yuntiku.entity.PagerQuestion;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class PagerquestionDaoImpl extends BaseDao implements PagerquestionDao {
    public int pagerquestioninsert(PagerQuestion pagerquestion){
        String sql = "INSERT INTO `yuntiku`.`pagerquestion` (`pagerid`, `questionid`) \n" +
                "VALUES(?,?);";
        return super.insertForId(sql,pagerquestion.getPagerid(),pagerquestion.getQuestionid());
    }
    /**
     * 根据试卷id获得试卷的题目
     * @param pagerId
     * @return
     */
    public List<Integer> selectByPagerId(int pagerId){
        List<Integer> list = new ArrayList<>();
        String sql="SELECT `questionid`\n" +
                "FROM `pagerquestion`\n" +
                "WHERE `pagerid`=?;";

        ResultSet rs = null;

        try {
            rs =super.executeQuery(sql,pagerId);
            while (rs.next()){
                list.add(rs.getInt(1));
            }
        }catch (SQLException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }finally {
            super.closeAll(conn,null,rs);
        }
        return list;
    }
}
